_F_l_o_c_k applies or removes an _a_d_v_i_s_o_r_y lock on the file associated with the
file descriptor _f_d. A lock is applied by specifying one of the following
as an _o_p_e_r_a_t_i_o_n parameter: LLLLOOOOCCCCKKKK____SSSSHHHH, LLLLOOOOCCCCKKKK____EEEEXXXX, LLLLOOOOCCCCKKKK____SSSSHHHH||||LLLLOOOOCCCCKKKK____NNNNBBBB or
LLLLOOOOCCCCKKKK____EEEEXXXX||||LLLLOOOOCCCCKKKK____NNNNBBBB. Note that LLLLOOOOCCCCKKKK____NNNNBBBB, if used, must appear in an inclusive
OR expression with either LLLLOOOOCCCCKKKK____SSSSHHHH or LLLLOOOOCCCCKKKK____EEEEXXXX. To unlock an existing
lock, _o_p_e_r_a_t_i_o_n should be LLLLOOOOCCCCKKKK____UUUUNNNN.
Advisory locks allow cooperating processes to perform consistent
operations on files, but do not guarantee consistency (i.e., processes
may still access files without using advisory locks, possibly resulting
in inconsistencies).
The locking mechanism allows two types of locks: _s_h_a_r_e_d locks and
_e_x_c_l_u_s_i_v_e locks. At any time multiple shared locks may be applied to a
file, but at no time are multiple exclusive, or both shared and
exclusive, locks allowed simultaneously on a file.
A shared lock may be _u_p_g_r_a_d_e_d to an exclusive lock, and vice versa,
simply by specifying the appropriate lock type; this results in the
previous lock being released and the new lock applied (possibly after
other processes have gained and released the lock).
Requesting a lock on an object that is already locked normally causes the
caller to be blocked until the lock may be acquired. If LLLLOOOOCCCCKKKK____NNNNBBBB is
included in _o_p_e_r_a_t_i_o_n, then this will not happen; instead the call will
fail and the error EEEEWWWWOOOOUUUULLLLDDDDBBBBLLLLOOOOCCCCKKKK will be returned.
NNNNOOOOTTTTEEEESSSS
Locks are on files, not file descriptors. That is, file descriptors
duplicated through _d_u_p(3C) (but not through _f_o_r_k(2), see the BUGS section
below) do not result in multiple instances of a lock, but rather multiple
references to a single lock. Thus if any of the descriptors associated
with the same file are closed, the lock associated with the file is lost.
Processes blocked awaiting a lock may be awakened by signals.
In C++, the function name _f_l_o_c_k collides with the structure name _f_l_o_c_k
(which is declared in <_s_y_s/_f_c_n_t_l._h> and included in <_s_y_s/_f_i_l_e._h> ). When
using _f_l_o_c_k() in C++, one must define ____BBBBSSSSDDDD____CCCCOOOOMMMMPPPPAAAATTTT before including